<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('流程定义明细列表')"/>
    <th:block th:include="include :: jasny-bootstrap-css"/>
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="formId">
                <div class="select-list">
                    <ul>
                        <li class="select-time">
                            <label>部署时间：</label>
                            <input type="text" class="time-input" id="startTime" placeholder="开始时间"
                                   name="params[beginDeployTime]"/>
                            <span>-</span>
                            <input type="text" class="time-input" id="endTime" placeholder="结束时间"
                                   name="params[endDeployTime]"/>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                    class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                    class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>
        <!--文件上传-->
        <div class="btn-group-sm" id="toolbar" role="group">
            <div id="uploadBtn" class="fileinput fileinput-new" data-provides="fileinput">
                <span class="btn btn-outline-secondary btn-file">
                    <span class="fileinput-new">
                    <a class="btn btn-warning btn-sm"><i class="fa fa-upload"></i>&nbsp;部署</a>
                </span>
                <span class="fileinput-exists">Change</span>
                    <input type="file" name="processDefinition" multiple>
                </span>
                <span class="fileinput-filename"></span>
                <a href="#" class="close fileinput-exists" data-dismiss="fileinput" style="float: none">&times;</a>
            </div>
        </div>
        <!--表格-->
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer"/>
<th:block th:include="include :: jasny-bootstrap-js"/>
<script th:inline="javascript">
    //文件上传
    var definitionId = [[${definitionId}]];//thymeleaf获取值得方法
    var prefix = ctx + "business/definitionDetail";//ctx上下文 / 部署时项目名
    $(function () {
        var options = {
            //url: prefix + "/list",
            url: prefix + "/list?definitionInfo.id=" + definitionId,
            modalName: "流程定义明细",
            //queryParams: queryParams,
            columns: [{
                checkbox: true
            },
                {
                    field: 'deploymentId',
                    title: '部署ID',
                    visible: false
                },
                {
                    field: 'definitionInfo.name',
                    title: '流程名称'
                },
                {
                    field: 'description',
                    title: '描述信息',
                    formatter: function (value, row, index) {
                        return $.table.tooltip(value, 5);
                    }
                },
                {
                    field: 'deployTime',
                    title: '部署时间'
                },
                {
                    field: 'deployKey',
                    title: '部署key'
                },
                {
                    field: 'version',
                    title: '版本号'
                },
                {
                    field: 'resourceName',
                    title: '查看流程文件',
                    formatter: function (value, row, index) {
                        var url = prefix + "/readResource?deployId=" + row.deploymentId + "&type=xml";
                        return '<a class="btn btn-info btn-xs " href="' + url + '" target="_blank"><i class="fa fa-search"></i></a> ';
                    }
                },
                {
                    field: 'diagramResourceName',
                    title: '查看流程图',
                    formatter: function (value, row, index) {
                        var url = prefix + "/readResource?deployId=" + row.deploymentId + "&type=png";
                        return '<a class="btn btn-info btn-xs " href="' + url + '" target="_blank"><i class="fa fa-search"></i></a> ';
                    }
                }]
        };
        $.table.init(options);
        initUploadBtn();
    });

   /* function queryParams(params) {
        params["definitionInfo.id"] = definitionId;
        return params;
    }*/

    //初始化按钮
    function initUploadBtn() {
        $('#uploadBtn').on('change.bs.fileinput', function (e) {
            //Ajax文件上传
            var formdata = new FormData();
            //获取文件上传的dom对象
            formdata.append("processDefinition", $('input[type=file]')[0].files[0]);
            formdata.append("definitionId", definitionId);
            $.ajax({
                url: prefix + '/upload',
                data: formdata,
                type: "post",
                processData: false,
                contentType: false,
                success: function (data) {
                    $('#uploadBtn').fileinput('reset');//重置提交框
                    $.operate.ajaxSuccess(data);//刷新表格
                }
            })
        });
    }

</script>
</body>
</html>